package reader;

import java.io.BufferedWriter;
import java.io.IOException;

import value_object.ResultVO;

/**
 * <p> This class is responsible for writing a result into a result file
 */

public class ResultReader extends Reader {
	/**
	 * "Results" directory
	 */
	private static final String FILE_DIRECTORY = "Results";
	
	/**
	 * the result file's name prefix
	 */
	private static final String FILE_NAME_PREFIX = "result";
	
	public ResultReader() {}	
	
	/**
	 * Overrides this method from the abstract one in the Reader superclass
	 * @return the result file's directory
	 */
	@Override
	public String getFile_directory() { return FILE_DIRECTORY; }
	
	/**
	 * Overrides this method from the abstract one in the Reader superclass
	 * @return the prefix name of the result file
	 */
	@Override
	public String getFile_name_prefix() { return FILE_NAME_PREFIX; }
	
	/**
	 * writes a result (object) into the result file
	 * @param result ResultVO object
	 * @throws IOException
	 */
	public void writeResult(ResultVO result) throws IOException {
		int x = result.getData_set_number();
		int y = result.getGrid_number();
		int z = result.getTrack_number();
		
		BufferedWriter bfWriter = getBufferedWriter(x, y, z);
		
		// I. result-information
	    bfWriter.write(x + " " + y + " " + z + "\n");
		
		// II. gain
		bfWriter.write((int)result.getGain() + "\n");
		
		//close buffered writer
		bfWriter.close();
	}
}
